local hx__wyorz = fk.CreateSkill {
  name = "hx__wyorz",
  tags = {Skill.Compulsory},
}


local spec = {
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, hx__wyorz.name)
    if player:isNude() or player.dead then return end
    local card = room:askToCards(player, {
      skill_name = hx__wyorz.name,
      include_equip = true,
      min_num = 1,
      max_num = 1,
      prompt = "#hx__wyorz",
      cancelable = false,
    })
    player:addToPile("hx__wyorz_juzi", card, true, hx__wyorz.name)
    if #player:getPile("hx__wyorz_juzi") >= 5 then
      if not player:hasSkill("hx__juzichiju",true) then
        room:handleAddLoseSkills(player, "hx__juzichiju")
      else
        player:setSkillUseHistory("hx__juzichiju", 0, Player.HistoryGame)
        room:setPlayerMark(player, "hx__juzichiju-phase", 0)
        room:sendLog{
          type = "%from 的“吃橘”已被重置",
          from = player.id,
        }
      end
    end
  end,
}

hx__wyorz:addEffect(fk.TurnStart, {
  derived_piles = "hx__wyorz_juzi",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(hx__wyorz.name)
  end,
  on_use = spec.on_use,
})

hx__wyorz:addEffect(fk.Damaged, {
  anim_type = "masochism",
  trigger_times = function(self, event, target, player, data)
    return data.damage
  end,
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(hx__wyorz.name)
  end,
  on_use = spec.on_use,
})


return hx__wyorz
